//  
//  Author:
//       Wouter Demuynck <wouter.am.demuynck@gmail.com>
// 
//  Copyright (c) 2011 Wouter Demuynck
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// 

using System;
using System.IO;

namespace HgSharp
{
	/// <summary>
	/// Represents a <b>Mercurial</b> repository.
	/// </summary>
	public class Repository
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="Repository"/> class using the specified
		/// working directory.
		/// </summary>
		/// <param name="path">
		/// The file system path of the repository to open.
		/// </param>
		public Repository(string path)
		{
			if (path == null) 
				throw new ArgumentNullException("path");
			if (path.Length == 0) 
				throw new ArgumentException("The specified path cannot be empty.", "path");
			if (!Directory.Exists(path)) 
				throw new ArgumentException("The specified path does not exist.", "path");
			if (!Directory.Exists(Path.Combine(path, ".hg"))) 
				throw new ArgumentException("The specified path exists, but is not a valid Mercurial repository.", "path");
			
			WorkingDirectory = path;
		}
		
		/// <summary>
		/// Gets the working directory of this <see cref="Repository"/>.
		/// </summary>
		public string WorkingDirectory
		{
			get;
			private set;
		}
		
		/// <summary>
		/// Updates the local working directory of this <see cref="Repository"/>.
		/// </summary>
		public void Update()
		{
			Hg.Update(WorkingDirectory);
		}
		
		/// <summary>
		/// Commits all changes to the working directory with the specified message.
		/// </summary>
		/// <param name='message'>
		/// The commit message.
		/// </param>
		public void Commit(string message)
		{
			Hg.Commit(WorkingDirectory, message);
		}
	}
}

